package de.jmda.gen.java.impl;

import javax.validation.constraints.NotNull;

import de.jmda.gen.GeneratorException;
import de.jmda.gen.impl.DefaultGenerator;
import de.jmda.gen.java.PackageStatementGenerator;

public class DefaultPackageStatementGenerator
		extends DefaultGenerator
		implements PackageStatementGenerator
{
	public final static String DEFAULT_PACKAGE_NAME = "default_package_name";

	public DefaultPackageStatementGenerator()
  {
		this(DEFAULT_PACKAGE_NAME);
  }

	public DefaultPackageStatementGenerator(String packagename)
  {
		super();
		setPackageName(packagename);
  }

	/**
	 * Adds "package " before and ";" after <code>super.generate()</code>.
	 *
	 * @see de.jmda.gen.impl.DefaultGenerator#getOutput()
	 */
	@Override
  public StringBuffer generate() throws GeneratorException
  {
	  return new StringBuffer("package ").append(super.generate()).append(";");
  }

	@Override
  public void setPackageName(@NotNull String packageName)
  {
		if (packageName == null)
		{
			throw new IllegalArgumentException("'packageName' must not be null");
		}

		setOutput(packageName);
  }

	@Override
	@NotNull
  public String getPackageName() throws GeneratorException
  {
		// return just the package name, not the whole package statement
	  return super.generate().toString();
  }
}